package org.quxiao.mmrsql.executor.test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.quxiao.mmrsql.executor.mapper.TableValueMapper;
import org.quxiao.mmrsql.executor.reducer.TableValueReducer;

public class TableValueTester {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		String tableName = "Asset_100000";
		String familyName = "MetaData";
		String qualifiedName = "vendor";
		String basePath = "/home/ubuntu/table_value_test/";
		
		Configuration conf = new Configuration();
		conf.set("tableName", tableName);
		Job job = new Job(conf, "TableValueTest");
		job.setJarByClass(TableValueTester.class);
		Scan scan = new Scan();
		scan.addColumn(familyName.getBytes(), qualifiedName.getBytes());
		TableMapReduceUtil.initTableMapperJob(tableName, scan, TableValueMapper.class, Text.class, Text.class, job);
		job.setReducerClass(TableValueReducer.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(Text.class);
		job.setOutputFormatClass(TextOutputFormat.class);
		TextOutputFormat.setOutputPath(job, new Path(basePath+"table_value_job_test_"+System.currentTimeMillis()));

		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}

}
